import Util from 'assets/js/util'
import PCUtil from '../pc-util'
export default {
  data () {
    return {
      pageNum: 1,
      pageSize: 10,
      searchList: {
        mobile: "",
        keyword: "",
        userType: 0,
        createDate: [],
        subjectType: -1
      },
      seekflag: true,
      isAsc: true,
      /*--------待审核-------*/
      //用户类型
      userTypeList: [
        {
          value: 0,
          label: '全部'
        },
        {
          value: '1',
          label: '实名用户'
        },
        {
          value: '2',
          label: '匿名用户'
        }
      ],
      subjectTypeList:[
        {
          "subjectId": -1,
          "subjectName": "全部"
        }
      ],
      //待审核列表
      PendingAuditList: false,
      dataTotal: 0,
      isClean:false,
      showWarnModal:false, //格式校验提示框
      warnContent:''  //提示文案
    }

  },
  mounted () {
    this.init();
  },
  beforeRouteEnter (to, from, next) {
    if(!('auditContent'==from.name || 'subjectDetail'==from.name)){
      sessionStorage.removeItem('search_con')
    }
    next();
  },
  methods: {
    init: function () {
      let routeName = this.$route.name;
      var _this = this;
      this.$http.post('convSubjectManage/getSubjectNameList')
        .then(function(resData){
          if (resData.meta.code == '0') {
            let data = resData.data;
            for(let i=0;i<data.length;i++){

            }
            _this.subjectTypeList = _this.subjectTypeList.concat(data);
          } else {
            // _this.$Modal.warning({
            //   title: '温馨提示',
            //   content: resData.meta.message
            // });
            _this.showWarnModal = true;
            _this.warnContent = resData.meta.message;
          }
        }).catch(function (err) {
        // _this.$Modal.warning({
        //   title: '温馨提示',
        //   content: err.meta.message
        // });
        _this.showWarnModal = true;
        _this.warnContent = err.meta.message;
      })
      if (routeName == "notAuditedList") {
        Util.setTitle('待审核列表');
        let oldParams=Util.sessionData('search_con'),param;
        console.log(oldParams);
        if(oldParams){
          param=oldParams;
          this.searchList = {
            mobile: oldParams.mobile,
            keyword: oldParams.keyword,
            userType:oldParams.userType,
            createDate: (oldParams.startCreateDate&&oldParams.endCreateDate)?[oldParams.startCreateDate,oldParams.endCreateDate]:[],
            subjectType: oldParams.subjectId
          };
          if(oldParams.isAsc ==1){
            this.isAsc= true;
          }else{
            this.isAsc= false;
          }

          // this.isAsc= oldParams.isAsc
          this.pageNum=oldParams.pageNum
        }else{
          param = {
            pageNum: 1,
            pageSize: this.pageSize,
            isAsc: this.isAsc ? 1 : 2
          }
        }
        this.queryPendingAuditList(param)
      }
    },
    /**
     *查看审核详情
     * @param params
     */
    viewReport(item){
      let params = {
        id: item.convId,
        isAsc : this.isAsc
      }
      this.$router.push({name: 'auditContent', params: params})
    },
    /*清空查询条件*/
    clearSearch: function () {
      this.isClean=true
      sessionStorage.removeItem('search_con')
      this.searchList = {
        mobile: "",
        keyword: "",
        userType: 0,
        createDate: [],
        subjectType: -1
      }
      //this.isAsc= false  不清空勾选
    },
    /**
     * 查询
     * @param param
     */
    pageNumChange: function (pageNum) {
      var _this=this;
      if(!this.seekflag)  return false;
      this.seekflag = false;
      setTimeout(function(){
        _this.seekflag = true;
      },2000);
      this.pageNum = pageNum ? pageNum : 1;
      if (this.searchList.mobile) {
        let isValidatePhone = /^1[34578]\d{9}$/.test(this.searchList.mobile)
        if (!isValidatePhone) {
          this.$Notice.warning({
            title: '温馨提示',
            desc: '手机号格式不正确',
            duration:2,
          });
          return false;
        }
      }
      var param = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        mobile: this.searchList.mobile,
        keyword: this.searchList.keyword,
        userType: this.searchList.userType ? this.searchList.userType : '',
        isAsc: this.isAsc ? 1 : 2,
        startCreateDate: PCUtil.date2TimeStamp(this.searchList.createDate[0]),
        endCreateDate: PCUtil.date2TimeStamp(this.searchList.createDate[1]),
        subjectId:  this.searchList.subjectType
      }
      this.queryPendingAuditList(param);
    },
    /**
     * 查询待审核列表接口
     * @param param
     */
    queryPendingAuditList(param){
      let _this = this;
      Util.sessionData('search_con',param);
      param.subjectId= param.subjectId==-1 ? "":param.subjectId
      console.log("param"+param.subjectId);
      this.$http.post('convphotoManage/queryPendingAuditList', param)
        .then(function (resData) {
          if (resData.meta.code == '0') {
            let data = resData.data;
            _this.dataTotal = data.dataTotal || 0;
            _this.pageCount = data.pageCount || 0;
            _this.PendingAuditList = data.result || [];
          } else {
            // _this.$Modal.warning({
            //   title: '温馨提示',
            //   content: resData.meta.message
            // });
            _this.showWarnModal = true;
            _this.warnContent = resData.meta.message;
          }
        })
        .catch(function (err) {
          // _this.$Modal.warning({
          //   title: '温馨提示',
          //   content: err.meta.message
          // });
          _this.showWarnModal = true;
          _this.warnContent = err.meta.message;
        })
    },

    /**
     * 选择创建时间
     * @param data
     */
    selectCreateDate(data){
      if (data.length == 2) {
        this.searchList.createDate[0] = data[0] + ' 00:00:00';
        this.searchList.createDate[1] = data[1] + ' 23:59:59';
      }
    },
    //查询专题详情
    goToSubject: function(item){
      console.log("audit"+this.PendingAuditList.subjectId);
      this.$router.push({
        name: "subjectDetail",
        query:{
          subjectId:item.subjectId
        }
      })
    },
    closeModal(){
      this.showWarnModal = false;
    },
    checknumber(){
        this.searchList.mobile =this.searchList.mobile.replace(/[^0-9]/g,'');
    }
  }
}
